<link rel="stylesheet" href="http://localhost/home/public/css/periodo.css" type="text/css" media="screen">
<script type="text/javascript"
	src="http://localhost/home/public/javascript/dias/dias.js"></script>
<div id="select-mes">
<?php
echo $this->form;
?>
</div>
<div id="selected-mes">
<?php
include 'functions.php';
$mdl = new Application_Model_Dia ();

$mdlValor = new Application_Model_DiaValorTotal ();

$saida = '';
$diferenca = diferenca ( '11-05-2012', '10-06-2012' );

$saldo = 740.79;

$saldoExtra = 300.00;

$contaLuz = 55.9;

$contaInternet = 120.20;

$cartao = 0;

$aluguel = 0;

$ganhoTotal = $saldo + $saldoExtra;

$gastoTotal = $contaInternet + $contaLuz + $cartao + $aluguel;

$total = ($ganhoTotal) - ($contaInternet + $contaLuz + $cartao + $aluguel);

$valores = array ('15', '30' );


$dia = 10;
$mes = 5;
$ano = 2012;
$dias_semana = array ('DOM', 'SEG', 'TER', 'QUA', 'QUI', 'SEX', 'SAB' );
$total_custo_dias = 0;
?>
<div id="tabela-dias">
	<table id="dias">
		<thead>
			<tr>
				<th>Dia</th>
				<th>Sigla</th>
				<th>Valor Total</th>
				<th>Mais</th>
				<th>Menos</th>
			</tr>

		</thead>
<?php

for($i = 0; $i < $diferenca; $i ++) {
	
	$timestamp = mktime ( 0, 0, 0, $mes, ($dia) + $i, $ano );
	
	$id_dia = $mdl->selectDay ( (date ( 'Y-m-d', $timestamp )) );
	
	?>
<tr>
<?php
	$dia_semana_corrido = date ( 'w', $timestamp );
	?>
	<td>
	<?php
	echo date ( 'd-m-Y', $timestamp );
	?>
	</td>
			<td>
	<?php
	echo $dias_semana [$dia_semana_corrido];
	?>
	</td>
			<td class="valor" id="<?php echo $id_dia['id_dia']; ?>">
	<?php
	$valor = $mdlValor->selectDay ( (date ( 'Y-m-d', $timestamp )) );
	if ($valor ['id_dia_valor_total'] == NULL) {
		$insert = array ('id_dia' => $id_dia ['id_dia'], 'valor' => $valores [0] );
		$mdlValor->insert ( $insert );
	} else {
		echo 'R$: ' . number_format ( $valor ['valor'], 2 );
		$total_custo_dias += $valor ['valor'];
	}
	?>
	</td>
			<td class="plus" align="center" id="<?php echo $id_dia['id_dia']; ?>"><span class="ui-icon ui-icon-plusthick"></span></td>
			<td align="center" class="minus"
				id="<?php echo $id_dia['id_dia']; ?>"><span class="ui-icon ui-icon-minusthick">menos</span></td>

		</tr>
<?php
}
?>
</table>
</div>
<div id="tabela-total">
	<table id="dias">
		<tr>
			<td>
				<div id="valor-final"><?php echo $total_custo_dias; ?></div>
			</td>
		</tr>
	</table>
</div>
</div>